package util

// CRC16Modbus CRC16Modbus算法校验
func CRC16Modbus(data []byte) uint16 {
	var crc16 uint16 = 0xFFFF

	for i := 0; i < len(data); i++ {
		crc16 = crc16 ^ uint16(data[i])
		for j := 0; j < 8; j++ {
			if (crc16 & 0x01) == 1 {
				crc16 = (crc16 >> 1) ^ 0xA001
			} else {
				crc16 = crc16 >> 1
			}
		}
	}
	return crc16
}
